Skip to content

BUG: Properly handle lists for .mask #21934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2018

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Jul 16, 2018

Title is self-explanatory.

Closes #21891.

@gfyoung gfyoung added Bug Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Jul 16, 2018
@gfyoung gfyoung added this to the 0.24.0 milestone Jul 16, 2018
@codecov
Copy link

codecov bot commented Jul 16, 2018

Codecov Report

Merging #21934 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21934      +/-   ##
==========================================
- Coverage   91.96%   91.96%   -0.01%     
==========================================
  Files         166      166              
  Lines       50329    50325       -4     
==========================================
- Hits        46287    46283       -4     
  Misses       4042     4042
Flag Coverage Δ
#multiple 90.36% <100%> (-0.01%) ⬇️
#single 42.22% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 96.46% <100%> (ø) ⬆️
pandas/core/groupby/generic.py 86.79% <0%> (-0.02%) ⬇️
pandas/core/sparse/series.py 95.2% <0%> (-0.02%) ⬇️
pandas/core/sparse/frame.py 94.78% <0%> (-0.02%) ⬇️
pandas/core/reshape/concat.py 97.59% <0%> (-0.01%) ⬇️
pandas/core/indexes/base.py 96.35% <0%> (-0.01%) ⬇️
pandas/core/series.py 94.11% <0%> (-0.01%) ⬇️
pandas/core/panel.py 97.44% <0%> (-0.01%) ⬇️
pandas/core/frame.py 97.19% <0%> (-0.01%) ⬇️
pandas/core/common.py 92.19% <0%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 537b65c...f3b3755. Read the comment docs.

@@ -7941,6 +7941,10 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
inplace = validate_bool_kwarg(inplace, 'inplace')
cond = com._apply_if_callable(cond, self)

# see gh-21891
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do this in .where itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do what exactly in .where ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i c we are using ~ here, ok then.

@@ -3010,6 +3010,14 @@ def test_mask_callable(self):
tm.assert_frame_equal(result,
(df + 2).mask((df + 2) > 8, (df + 2) + 10))

def test_mask_list(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you pas a bunch of list-likes in a fixture (the old box argument)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old box argument? Sorry, I'm not sure what you mean here (or I forgot what it meant if you have mentioned it to me before).

@@ -582,6 +582,15 @@ def test_where_dt_tz_values(tz_naive_fixture):
assert_series_equal(exp, result)


def test_where_list():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test where as well with array-likes for the cond

Copy link
Member Author

@gfyoung gfyoung Jul 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test where as well with array-likes for the cond

That's tested pretty heavily for DataFrame and Series already in fact in the test files that I have modified in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok can u integrate this test in a related one then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but I was more comfortable leaving it as a separate test semantically speaking. After all, it is more atomic that way IMO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but it is not clear not where things are tested. we are apparently testing list-likes (ex list) somewhere else, so this is confusing to a new reader and is just future technical debt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Integrated.

@gfyoung gfyoung force-pushed the mask-invert-cond branch from b2823a0 to f3b3755 Compare July 17, 2018 16:04
@@ -7941,6 +7941,10 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
inplace = validate_bool_kwarg(inplace, 'inplace')
cond = com._apply_if_callable(cond, self)

# see gh-21891
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cond could be a callable , this patch seems wouldn't work.

Copy link
Member Author

@gfyoung gfyoung Jul 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would. Because com._apply_if_callable (right above) returns an ndarray. Passing in callable for cond is covered (and passing) in the tests.

@jreback jreback merged commit ce87d06 into pandas-dev:master Jul 17, 2018
@jreback
Copy link
Contributor

jreback commented Jul 17, 2018

thanks @gfyoung

@gfyoung gfyoung deleted the mask-invert-cond branch July 17, 2018 19:47
aeltanawy pushed a commit to aeltanawy/pandas that referenced this pull request Jul 20, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants